(* Fichier principal du programme *)


let display img =
 (*Fonction permettant d'afficher l'image a l'ecran. En attendant l'interface graphique.*)
 (*Prend un int array array en parametre *)
  begin
      Graphics.open_graph("");
      Graphics.set_window_title("Land Rush Project");
      Graphics.resize_window (Array.length img.(0)) (Array.length img);
      let finalimg = Graphics.make_image img in
        Graphics.draw_image finalimg 0 0;
        Sys.command "sleep 5";
  end

let rec display_height = function
    [] -> ()
  | e::l -> print_string ("Couleur = "^(string_of_int e.Types.color)^" - hauteur = "^(string_of_int e.Types.height)^"\n");
      display_height l

let printpos2 pos id = 
  print_string ("Vertex "^(string_of_float id)^" : {x="^(string_of_float pos.Types.x)^"; y="^(string_of_float pos.Types.y)^"; z="^(string_of_float pos.Types.z)^"}\n")

let printpos pos =
    print_string ("{x="^(string_of_float pos.Types.x)^"; y="^(string_of_float pos.Types.y)^"; z="^(string_of_float pos.Types.z)^"}\n")


let display_vertices vertmat =
  let (w,h) = (Array.length vertmat, Array.length vertmat.(0)) in
    for i = 0 to w-1 do
      for j = 0 to h-1 do
	printpos2 vertmat.(i).(j) (float_of_int(i*j));
      done;
    done;
    print_string ("Total vertex nb = "^string_of_int(h*w)^"\n")
	

let display_triangles triangle_tab =
  let t = Array.length triangle_tab in 
    for i=0 to t-1 do
      print_string ("Triangle "^(string_of_int i)^" : ");
      printpos triangle_tab.(i).Types.p1;
      printpos triangle_tab.(i).Types.p2;
      printpos triangle_tab.(i).Types.p3;
      printpos triangle_tab.(i).Types.norm;
    done;
    print_string ("Total triangles nb = "^(string_of_int (t-1))^"\n")

let _ =
  (*Fonction d'entree du programme*)
  if Array.length (Sys.argv) < 2 then
    failwith "Error : please specify a file name. ";
  Interface.main
(*  let image = BoarderProcess.transform (OImages.rgb24 (OImages.load Sys.argv.(1) [])) in
  let image_copy = BoarderProcess.transform (OImages.rgb24 (OImages.load Sys.argv.(1) [])) in
  let image_f = BoarderProcess.border_f image (BoarderProcess.border_w image) (BoarderProcess.border_h image) in
  let listheight = ColorParser.detection image in
  let matpos = Sampler.create_vertices image_copy listheight in
  let triangles = Sampler.triangulation matpos in
  let grid = Sampler.create_grid image_f in 
    Obj_manager.write_obj triangles;
    display_vertices matpos;
    display_triangles triangles;
    display_height listheight;
    display grid*)

(*EOF*)
